package net.bwie;

import cn.hutool.http.useragent.UserAgent;
import cn.hutool.http.useragent.UserAgentUtil;
import org.apache.hadoop.hive.ql.exec.UDF;

import java.util.HashMap;
import java.util.Map;

public class parseUaToBrowase extends UDF {
    public Map<String,String> evaluate(String userAgent) throws Exception{
        Map<String,String> map = new HashMap<String,String>();

        UserAgent ua = UserAgentUtil.parse(userAgent);

        map.put("browser", ua.getBrowser().toString());
        map.put("browser_version", ua.getVersion());
        map.put("engine", ua.getEngine().toString());
        map.put("engine_version", ua.getEngineVersion());
        map.put("os", ua.getOs().toString());
        map.put("os_version", ua.getOsVersion());
        map.put("platform", ua.getPlatform().toString());
        map.put("is_mobile", ua.isMobile() ? "1" : "0");

        return map;
    }
    public static void main(String[] args) throws Exception{
        System.out.println(new parseUaToBrowase().evaluate("Mozilla/5.0 (X11; U; Linux i686; Ubuntu 7.04; de-CH; rv:1.8.1.5)" +
                " Gecko/20070309 Firefox/2.0.0.5"));
    }
}
